<template>
	<view>
		<cu-custom :bgColor="'bg-white'" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">列表</block>
		</cu-custom>
	
		
		
	
		
		
		<xg-waterfall  :column-count="2" :left-gap="12" :right-gap="12">
		    <xg-waterfall-header>
	
		    </xg-waterfall-header>
		    <xg-waterfall-item v-for="(item,k) in posts" :key="index">
				<view class="bg-white margin-xs radius" @tap="detail" :data-id="item.id">
					<image :src="item.thumb" class="radius" mode="aspectFill" ></image>
					<view class="text-bold text-black padding-tb-sm">
						{{item.title}}
					</view>
					<view class="text-sm flex">
						<view class='text-blue bg-white text-bold margin-right-xs' v-for="(item,index) in item.tag" :key="index">#{{item}}</view>
						
					</view>
				</view>
				
		    </xg-waterfall-item>
		    <xg-waterfall-footer>
				
		    </xg-waterfall-footer>
		</xg-waterfall>
	
		
		<!-- 空 -->
		<view class="text-center" style="margin-top: 60%;" v-if="posts.length <=0">
			<image src="../../static/images/empty.png"  mode="aspectFill" style="width: 250rpx;height: 250rpx;"></image>
		</view>
		
		<!-- 加载 -->
		<view v-if="isloding" class="cu-load" :class="!isLoad?'loading':'over'"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isloding:false,
				isLoad:true,
				page:1,
				category_id:0,
				posts:[],
			}
		},
		onLoad(options) {
			this.category_id = options.id
			
			this.getPosts();
		},
		onReachBottom() {
			this.page = this.page + 1;;
			this.getPosts();
		},
		methods: {
			getPosts(){
				const _this = this;
				var page = _this.page;
				var category_id = _this.category_id;
				_this.$apiResquest({
					url: 'cms/getPostByCategory',
					method: 'GET',
					query:{page,category_id}
				}).then(function(res) {
					if(res.data.data.length <=0){
						_this.isLoad = true;
					}
					_this.posts = _this.posts.concat(res.data.data)
					_this.loading = true
				
				})
			},
			detail: function(e) {
				let id = e.currentTarget.dataset.id
				uni.navigateTo({
					url: '../detail/detail?id='+id
				})
			},
		}
	}
</script>

<style>

</style>
